%Gitee Repo

clc
clear

L = 5;
dx = 0.1;
dt = 0.001;
D=1;
TICK = 10000;

sigma = D*dt/(dx)^2;

x = 0:dx:L;
n = size(x,2);
u0 = zeros(n,1);
u1 = zeros(n,1);
u0(int32(n/2)) = 10;

figure();

for tick = 1:TICK
  t = tick*dt;
  %  for i = 2:n-1
  %    u1(i) = u0(i) + sigma*(u0(i+1)-2*u0(i)+u0(i-1));
  %  endfor

  % 根据AI的建议向量化
  u1(2:n-1) = u0(2:n-1) + sigma * (u0(3:n) - 2 * u0(2:n-1) + u0(1:n-2));

  % 边界条件
  u1(1) = 0;
  u1(n) = 0;

  u0=u1;

  clf
  hold on
  axis equal
  axis([0 L -2 2])

  plot(x,u1)
  pause(0.01)
end
